﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Linq;
using appladen.contracts;
using appladen.contracts.data;

namespace appladen.gui
{
    public class Map : IMap
    {
        private IViewmodel _viewmodel;

        #region IMap Members

        public void Inject(IViewmodel independent)
        {
            _viewmodel = independent;
        }

        public void Process(Seite message)
        {
            Trace.TraceInformation("Map To ViewModel");

            var dt = new DataTable();
            foreach (var h in message.Header.Werte)
                dt.Columns.Add(h);

            foreach (var zeile in message.Zeilen)
            {
                var row = dt.NewRow();
                for (var i = 0; i < zeile.Werte.Count(); i++)
                    row[i] = zeile.Werte.ElementAt(i);
                dt.Rows.Add(row);
            }
            _viewmodel.Table = dt;
        }

        public void Process(Tuple<CSVZeile, IEnumerable<CSVZeile>> message)
        {
          
        }

        #endregion
    }
}